package com.hb.trade.api.routine.config.web;

import feign.FeignException;
import lombok.extern.slf4j.Slf4j;
import org.fzzn.core.model.msg.ResponseDto;
import org.fzzn.core.util.ResultUtil;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一异常处理类<br>
 * 捕获程序所有异常，针对不同异常，采取不同的处理方式
 *
 * @author zhaojk
 */
@Slf4j
@RestControllerAdvice
public class ExceptionHandleController {

    /**
     * 微服务异常处理
     *
     * @param ex
     * @return
     */
    @ExceptionHandler(FeignException.class)
    public ResponseDto handleFeignException(FeignException ex) {
        log.error("微服务异常, {}", ex.getMessage(), ex);
        return ResultUtil.msg(ex.status(), ex.getMessage());
    }

    /**
     * 其他异常返回
     *
     * @param ex
     * @return
     */
    @ExceptionHandler(Exception.class)
    public ResponseDto handleException(Exception ex) {
        log.error("其他异常, {}", ex.getMessage(), ex);
        return ResultUtil.msg(500, ex.getMessage());
    }

}
